package org.example.product.controller;


import org.example.core.utils.PageUtils;
import org.example.core.utils.R;
import org.example.core.valid.group.AddGroup;
import org.example.core.valid.group.UpdateGroup;
import org.example.product.entity.BrandEntity;
import org.example.product.service.BrandService;
import org.example.product.vo.BrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author 小杰_cc
 * @version 1.0
 */
@RestController
@RequestMapping("/pms/backend/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R<PageUtils> list(@RequestParam(defaultValue = "1") Integer pageNum
                    ,@RequestParam(defaultValue = "10") Integer pageSize
                    ,@RequestParam(required = false) String name
                    ,@RequestParam(required = false) String firstLetter){

        PageUtils vos = brandService.queryBrandList(pageNum, pageSize, name, firstLetter);
        return R.ok(vos);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R<BrandEntity> info(@PathVariable("id") Long id){
        BrandEntity entity = brandService.queryBrandInfoById(id);
        return R.ok(entity);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R<?> save(@Validated(value = {AddGroup.class}) @RequestBody BrandEntity brandEntity){
        return brandService.saveBrandInfo(brandEntity)>0? R.ok():R.error();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R<?> update(@Validated(value = {UpdateGroup.class}) @RequestBody BrandEntity brandEntity){
        return brandService.editBrandInfo(brandEntity)>0? R.ok():R.error();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R<?> delete(@RequestBody List<Long> ids){
        return brandService.deletes(ids);
    }
}
